﻿
using Knlght.Domain;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knight.Models.Entity
{
    public class NewsType:TEntityBase
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int ParentId { get; set; } = 0;
        public int DisplayIndex { get; set; }
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnabled { get; set; }

        public List<NewsType> Nodes { get; set; }
    }
    public class NewsTypeMapping : EntityTypeConfiguration<NewsType>
    {
        public NewsTypeMapping()
        {
            // 设置表名
            this.ToTable("T" + nameof(NewsType));
            //设置主键
            this.HasKey(p => p.Id);
            //自增
            this.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            //忽略列映射
            this.Ignore(p => p.Nodes);
            //不更新
            //this.Property(t => t.AddTime).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            // 设置属性的类型和长度
            this.Property(p => p.Name).HasColumnType("NVarchar").HasMaxLength(500);
        }
    }

}
